
var FormData = require( 'form-data' );
var fs = require( 'fs' );
const fetch = require( 'node-fetch' )
module.exports = class extends think.global.service {
  async indexAction () {
    var formData = new FormData()
    formData.append( 'image', fs.createReadStream( this.file( 'image' ).path ) )
    try {
      var result
      await fetch( this.$url, { method: 'POST', body: formData } ).then( function( res ) {
        return res.json()
      } ).then( function( json ) {
        result = json
      } )
      this.json( result )
    } catch ( e ) {
      this.ctx.fail( 1000, e.message )
    }
  }
};
